<template>
<div id="train">
  <div id="trainAuth">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/train' }">干部培训</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/trainperson' }">全部人员</el-breadcrumb-item>
      <el-breadcrumb-item>数据分析</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs" :style="'height:'+tableHeight+'px'">
      <el-row :gutter="20" style="margin:20px;">
        <el-col :span="12">
          <el-select v-model="theyear" placeholder="请选择" @change="getData" style="float:right;z-index:1000">
            <el-option label="全部" :value="null"></el-option>
            <el-option v-for="(item, index) in yearlist" :key="index" :label="item" :value="item"></el-option>
          </el-select>
          <Chart class="indexchart" id="mytest" height="500px" width="100%" :option="option" />
        </el-col>
        <el-col :span="12">
          <Chart class="indexchart" id="mytest2" height="500px" width="100%" :option="option2" />
        </el-col>
      </el-row>
    </section>
  </div>
</div>
</template>

<script>
import Chart from '@/components/Chart.vue'
export default {
  components: {
    Chart
  },
  data () {
    return {
      yearlist: [],
      tableHeight: null,
      theyear: null,
      option2: {
      },
      option: {
      }
    }
  },
  methods: {
    getYearList () {
      this.$http
        .get(this.$http.defaults.trainingAPI + `api/trainingBusFiledCandidate/getAllYears`)
        .then(response => {
          if (response.data.success === true) {
            this.yearlist = response.data.result
          }
        })
        .catch((error) => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getData () {
      this.$http
        .get(this.$http.defaults.trainingAPI + `api/trainingBusFiledCandidate/getAnalyseData?year=` + (this.theyear ? this.theyear : ''))
        .then(response => {
          let seriesData = response.data.result.chart1.map(item => { return {value: item.num, name: item.unitName ? item.unitName : '未知单位'} })
          this.option = {
            title: {
              text: '部直属单位局级干部参加培训情况分析表',
              subtext: this.theyear ? this.theyear + '年度' : '',
              left: 'left'
            },
            tooltip: {
              trigger: 'item'
            },
            legend: {
              top: '10%',
              orient: 'vertical',
              left: 'right'
            },
            series: [
              {
                name: '参加培训人次',
                type: 'pie',
                radius: '50%',
                data: seriesData,
                emphasis: {
                  itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                  }
                }
              }
            ]}
          this.option2 = {
            title: {
              text: '历年局级干部参加培训情况分析图',
              left: '50px'
            },
            tooltip: {
              trigger: 'axis'
            },
            xAxis: {
              type: 'category',
              data: response.data.result.chart2.map(item => item.year)
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                name: '参加培训人次',
                data: response.data.result.chart2.map(item => item.num),
                type: 'line'
              }
            ]
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 172
      })
    }
  },
  mounted () {
    this.getYearList()
    this.getData()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  #train .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
  }
  #train .wboxd .el-table td,
  #train .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体'
  }
  #train .el-table--border th,
  #train .el-table--border td {
    border-right: 1px solid #95B8E7;
  }
  #train .el-table th.is-leaf,
  #train .el-table td {
    border-bottom: 1px solid #95B8E7;
  }
  #train .el-table td{
    border-right: 1px solid #95B8E7;
    border-bottom: 1px solid #95B8E7;
  }

</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  #trainAuth .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  #trainAuth .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
